package com.mars.diancan.pojo.mapper;

import com.mars.diancan.pojo.ProductCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author MARS
 * @date 2018/7/12
 */
public interface ProductCategoryDao {

    @Insert("insert into wx_product_category(category_name,category_type,create_time,update_time) values(#{categoryName,jdbcType=VARCHAR},#{categoryType,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})")
     int insert(ProductCategory productCategory);

    @Select("select * from wx_product_category where category_type = #{categoryType,jdbcType=INTEGER}")
    @Results({
            @Result(column = "category_id",property = "categoryId"),
            @Result(column = "category_name",property = "categoryName"),
            @Result(column = "category_type",property = "categoryType"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime")

    })
     ProductCategory findByCategoryType(Integer categoryType);

    @Select("select * from wx_product_category where category_name = #{categoryName,jdbcType=VARCHAR}")
    @Results({
            @Result(column = "category_id",property = "categoryId"),
            @Result(column = "category_name",property = "categoryName"),
            @Result(column = "category_type",property = "categoryType"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime")

    })
     List<ProductCategory> findByCategoryName(String categoryName);


    /**
     * update传入多参数时，需要使用@Param注解
     * @param categoryId
     * @param categoryName
     * @return
     */
    @Update("update wx_product_category set category_name=#{categoryName} where category_id=#{categoryId}")
     int updateCategoryType(@Param("categoryId") Integer categoryId,@Param("categoryName")String categoryName);

    @Update("update wx_product_category set category_name=#{categoryName} where category_id=#{categoryId}")
     int updateObject(ProductCategory productCategory);


    @Delete("delete from wx_product_category where category_type = #{categoryType}")
     int deleteByCategoryType(Integer categoryType);

    /**
     * 使用xml的形式整合mybatis:
     * 1、需要在resource下创建mapper包，创建与da接口类同名的xml文件
     * 2、配置与mapper.xml关联的配置参数，在.yml中配置
     * @param categoryType
     * @return
     */
    ProductCategory selectByCategoryTypeXML(Integer categoryType);
}
